package com.example.demo.controller;

import com.example.demo.modal.Concept;
import com.example.demo.service.ConceptService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/concept")
@RequiresPermissions("add")
public class ConceptController {

    @Autowired
    private ConceptService conceptService;


    @GetMapping
    public String getTable() {
        return "concept";
    }


    @PostMapping("/index/data")
    @ResponseBody
    public List<Concept> data(){
        return conceptService.findAll();
    }

    @PostMapping("/index/add")
    @ResponseBody
    public String addConcept(@RequestBody Concept concept){
        conceptService.addConcept(concept);
        return "添加成功！";
    }

    @PostMapping("/index/maxid")
    @ResponseBody
    public Integer findMaxId(){
        return conceptService.findMaxId();
    }

    @PostMapping(value = "/index/update")
    @ResponseBody
    public String update(@RequestBody Concept concept){
        conceptService.updateConcept(concept);
        return "更改成功！";
    }

    @PostMapping(value = "/index/delete")
    @ResponseBody
    public String delete(@RequestParam("id") Integer id){
        conceptService.deleteConcept(id);
        return "删除成功！";
    }

    @PostMapping("/index/find/conceptid")
    @ResponseBody
    public List<Concept> find_conceptid(@RequestParam("id") Integer id){
        return  conceptService.findByConceptId(id);

    }

    @PostMapping("/index/find/varianame")
    @ResponseBody
    public List<Concept> find_varianame(@RequestParam("name") String name){
        return  conceptService.findByVariaName(name);
    }

    @PostMapping("/index/find/parentid")
    @ResponseBody
    public List<Concept> find_parentid(@RequestParam("parentid") Integer id){
        return  conceptService.findByParentId(id);
    }
}
